package MP
{
    import flash.geom.Point;

    public class MapVO 
    {

        public var mapId:int;
        public var previewImageUrl:String;
        public var tileArray:Array;
        public var mapWidth:int = 0;
        public var mapHeight:int = 0;
        public var nodeWidth:int;
        public var nodeHeight:int;
        public var tileWidth:int;
        public var tileHeight:int;
        public var nodeArray:Array;
        public var row:uint = 0;
        public var col:uint = 0;
        public var doors:Array;
        public var version:String = "";
        public var mapEffectList:Array;
        public var name:String = "";
        public var special:Array;
        public var startNode:Node;
        public var endNode:Node;
        public var isHasWeixianArea:Boolean;

        public static function getNodeByPixelXY(px:int, py:int):Point
        {
            var x:int = (px / MapConfig.MAP_NODE_WIDTH);
            var y:int = (py / MapConfig.MAP_NODE_HEIGHT);
            return (new Point(x, y));
        }
        public static function transNodePoint(node:Node, p:Point=null):Point
        {
            if (p == null)
            {
                p = new Point(0, 0);
            };
            p.x = ((node.x + 0.5) * MapConfig.MAP_NODE_WIDTH);
            p.y = ((node.y + 0.5) * MapConfig.MAP_NODE_HEIGHT);
            return (p);
        }
        public static function getCenterPoint(nodex:int, nodey:int):Point
        {
            var p:Point = new Point();
            p.x = ((nodex + 0.5) * MapConfig.MAP_NODE_WIDTH);
            p.y = ((nodey + 0.5) * MapConfig.MAP_NODE_HEIGHT);
            return (p);
        }
        public static function getPoint(node:Node, px:int=0, py:int=0):Point
        {
            var point:Point = new Point();
            point.setTo(((node.x * MapConfig.MAP_NODE_WIDTH) + px), ((node.y * MapConfig.MAP_NODE_HEIGHT) + py));
            return (point);
        }
        public static function getDistanceBy2Point(cx:Number, cy:Number, tx:Number, ty:Number):int
        {
            var xDis:int = Math.abs((Math.ceil((cx / MapConfig.MAP_NODE_WIDTH)) - Math.ceil((tx / MapConfig.MAP_NODE_WIDTH))));
            var yDis:int = Math.abs((Math.ceil((cy / MapConfig.MAP_NODE_HEIGHT)) - Math.ceil((ty / MapConfig.MAP_NODE_HEIGHT))));
            var distanceGrid:int = ((xDis > yDis) ? xDis : yDis);
            return (distanceGrid);
        }

        public function dispose():void
        {
            var a:Array;
            var n:Node;
            if (this.nodeArray)
            {
                for each (a in this.nodeArray)
                {
                    for each (n in a)
                    {
                        n.dispose();
                    };
                };
                this.nodeArray = null;
            };
            this.mapEffectList = null;
        }
        public function nodesRest():void
        {
        }
        public function getNodeByXY(px:int, py:int):Node
        {
            var x:int = (px / this.nodeWidth);
            var y:int = (py / this.nodeHeight);
            return (this.getNode(x, y));
        }
        public function getNode(px:int, py:int):Node
        {
            if (((((py >= 0) && (px >= 0)) && (py < this.row)) && (px < this.col)))
            {
                return (this.nodeArray[py][px] as Node);
            };
            return (null);
        }

    }
}//package yr_engine.scene.map.libarys
